<?php


class PlaceDepartmentsController extends AppController{
    public $uses = array('Place', 'PlaceCity', 'PlaceState', 'PlaceDepartment');
    
     public $layout = 'place';
     
    public function view($id){
        $department = $this->PlaceDepartment->find('first', array(
            'conditions' => array(
                'PlaceDepartment.places_id' => $id
            ),
            'fields' => array(
            )
        ));
        
        $this->set('department', $department);
        
    }
    
    
    public function admin_edit($id){
        
        $this->layout = 'admin';
        $model = 'PlaceCity';
        $type = 'City';
        $currentModel = 'PlaceDepartment';
        
        if (!empty($this->request->data[$model])){
            $data = $this->request->data[$model];
            
            $idReturn = $this->Place->save(array('Place' => array('type' => $type)), array('update' => 'false'));
            
            if ($idReturn != null){
                $data['places_id'] = $idReturn['Place']['id'];
                $this->$model->save($data);
            }
        }
        
        $data = $this->$currentModel->find('first', array(
            'conditions' => array(
                $currentModel.'.places_id' => $id
            ),
        ));
        
        $this->set('data', $data);
        
    }
    
    
    public function beforeFilter() {
        parent::beforeFilter();
        $this->Auth->allow( 'view');
    }
    
}
?>
